﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MySql.Data.MySqlClient;

namespace SqlMidasala
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        private Globals g = new Globals();
        private sql Sql = new sql();

        string atburdur = null;

        public Window1()
        {
            InitializeComponent();
            dataGridView.CanUserAddRows = false;
            dataGridView.CanUserDeleteRows = false;
            dataGridView.CanUserReorderColumns = false;
            dataGridView.CanUserResizeColumns = false;
            dataGridView.CanUserResizeRows = false;
            dataGridView.CanUserSortColumns = false;
            dataGridView.Focusable = false;
            dataGridView.IsReadOnly = true;
            if (!Sql.SetLink())
                MessageBox.Show("Tókst ekki að koma á tengingu við gagnagrunn","Villa í tengingu",MessageBoxButton.OK,MessageBoxImage.Error);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            List<string> listinn = new List<string>();
            listinn = Sql.GetTableList();

            for (int i = 0; i < listinn.Count; i++)
                comboBox1.Items.Add(listinn[i]);
        }

        private void buttonAddGuest_Click(object sender, RoutedEventArgs e)//Skrá í töflu
        {
            //Setja upplýsingar í viðeigandi töflu
            string nafn, id, heimilisfang, simanumer, athugasemd;
            id = textBoxID.Text;
            nafn = textBoxName.Text;
            heimilisfang = textBoxAddress.Text;
            simanumer = textBoxPNumber.Text;
            athugasemd = textBoxInfo.Text;

            Sql.AddGuset(id, nafn, simanumer, athugasemd);
            Sql.SellTicket(id,atburdur);
        }

        private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)//Svo rétt event sé alltaf valið
        {
            atburdur = comboBox1.Text.ToString();            
        }

        private void radioButtonSell_Checked(object sender, RoutedEventArgs e)
        {
            dataGridView.ItemsSource = g.Guests;
            dataGridView.DataContext = g.Guests;
        }

        private void radioButtonAdd_Checked(object sender, RoutedEventArgs e)
        {
            dataGridView.ItemsSource = g.Events;
            dataGridView.DataContext = g.Events;
        }
    }
}
